package com.sxt.quartz.config;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import com.sxt.quartz.jobs.QuartzJob2;
/**
 * Quartz配置类
 * @author Administrator
 *
 */
@Configuration
public class QuartzConfig2 {
	/**
	 * 1.创建Job对象
	 */
	@Bean
	public JobDetail teatQuartzDetail() {
		 return JobBuilder.newJob(QuartzJob2.class).withIdentity("quartzJob2").storeDurably().build();
	}
	
	/**
	 * 2.创建Trigger对象（简单Trigger）
	 */
	@Bean
	 public Trigger testQuartzTrigger(){
		 SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
				 .withIntervalInSeconds(10)  //设置时间周期单位秒
				 .repeatForever();
		return TriggerBuilder.newTrigger().forJob(teatQuartzDetail())
				.withIdentity("quartzJob2")
				.withSchedule(scheduleBuilder)
				.build();
	}
}
